$(document).ready(function () {
    var roleArray = $('#roleList').attr("value").split(",");
    $.each(roleArray, function (idx, val) {
        var user_role = $("input[type=checkbox][name='user_roles'][value='"+val+"']");
        if(user_role){
            user_role.attr('checked','checked');
        }
    });
});
$('#account_form').ajaxForm({
    dataType:'json',
    beforeSubmit:function () {
        if (!$.isValid()) {
            return false;
        }
        var roleArray = new Array();
        $("[name='user_roles']:checked").each(function () {
            roleArray.push($(this).attr("value"));
        });
        $('#roleList').attr("value", roleArray.join(","));
        if (!$('#roleList').val()) {
            cdms.common.show_error('tr_form_msg', language.pwd_chooce_role);
            return false;
        }
        $('#btn_submit').attr('disabled', 'disabled');
        cdms.common.show_info('tr_form_msg', language.project.wait_submit_msg);
    },
    success:function (json) {
        $('#btn_submit').removeAttr('disabled');
        if (json.type) {
            $.alert({
                title:language.note.alert_title,
                message:json.msg,
                fnOk:function () {
                    window.location.href = "list";
                }
            });
        } else {
            cdms.common.show_error('tr_form_msg', json.msg);
        }
    }
});
